home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Libraries / Animation Class Library / CCL / Core Class Library V1.1c / Headers / CoreHead.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-06  |  9.2 KB  |  249 lines  |  [TEXT/MPCC]

  1.  
  2. /********************************************
  3.  **** Core Class V1.1 © 1993-94 Yves Schmid & Alia Development
  4.  ****
  5.  **** CoreHead.h
  6.  ****
  7.  **** Authors:        Yves Schmid and Odorico von Susani
  8.  **** Created:      15 November 1993
  9.  **** Modified:     08 August 1994
  10.  **** Compatible:   C++
  11.  **** Version:        1.1
  12.  **** Description:  CoreHead is the most advanced class of the Core Class package. Basically,
  13.  ****                a CoreHead is a CoreNode with various CoreLists under its control.
  14.  ****                CoreHead allows you to build complex tree structures. CoreLists under
  15.  ****                the control of a CoreHead are called entries.
  16.  ****
  17.  ****
  18.  ****                For example:
  19.  ****
  20.  ****                
  21.  ****                                                        |-CoreHead...
  22.  ****                                    |-CoreHead.entry0---|-CoreHead...
  23.  ****                CoreHead.entry0-----|-CoreHead...
  24.  ****                                    |-CoreHead...
  25.  ****                        
  26.  ****                        .entry1-----|-CoreHead...
  27.  ****                        .entry2...
  28.  ****
  29.  ****
  30.  ****
  31.  ****                 A CoreHead may have as many entries as the user want (and the memory can).
  32.  ****                Each CoreHead has only one entry for a simple tree structure . If
  33.  ****                you want that a CoreHead controls different kind of data, you may
  34.  ****                want to create more than one entry. For example you can have
  35.  ****                an object which controls a list of picture, a list of sound, etc...
  36.  ****
  37.  ****                A CoreHead with other CoreHeads under its control is called
  38.  ****                a supervisor. Each CoreHead has a pointer on his supervisor (or
  39.  ****                NULL if there is no supervisor).
  40.  ****
  41.  ****                When you create a CoreHead you define his number of entries.
  42.  ****                Default is zero entry. If a CoreHead does not have objects under
  43.  ****                its control, it does not need entries.
  44.  ****
  45.  ****                It is possible to place a simple CoreNode under the control
  46.  ****                of a CoreHead. However it is not very flexible because
  47.  ****                a CoreNode is not smart enough to know who its supervisor is.
  48.  ****                It means that messages cannot follow an ascendant tree. When
  49.  ****                they meet a CoreNode they are stopped.
  50.  ****
  51.  ****                Commands may be sent in a complexe CoreHead structure. There
  52.  ****                is a flag called "CCF_EVERYWHERE" which allows you to send a command
  53.  ****                to every CoreHead in the structure from everywhere. Each CoreHead
  54.  ****                will only receive the message once! See "CoreCmd.h" to
  55.  ****                learn more about flags.
  56.  ****
  57.  ****                You can change the supervisor of a CoreHead with
  58.  ****                the "setsupervisor" method. This method allows you to specify a pointer
  59.  ****                on the new supervisor and the entry which will receive the object.
  60.  ****                You can pass NULL to unlink your CoreHead.
  61.  ****
  62.  ****                It is legal to add a CoreHead to a simple CoreList (not to a CoreHead) with
  63.  ****                the "setlist" method. However your object will not have a
  64.  ****                supervisor, because a CoreList is not smart enough to be a
  65.  ****                supervisor.
  66.  ****
  67.  ****                When you duplicate a CoreHead, all object under its control in
  68.  ****                all entries are duplicated too. The duplicated CoreHead is linked
  69.  ****                to the same entry as the orignal CoreHead. Use "remove" to
  70.  ****                unlink the object.
  71.  ****
  72.  ****                The CoreHead destructor unlinks the object from his supevisor and
  73.  ****                deletes all the objects under its control. You can delete a complexe
  74.  ****                CoreHead structure with a single call like "delete baseCoreHead".
  75.  ****
  76.  ****
  77.  ****
  78.  *************************/
  79.  
  80.  
  81. #ifndef CoreHead_H
  82. #define CoreHead_H
  83.  
  84. #include "Core.h"
  85. #include "CoreNode.h"
  86. #include "CoreList.h"
  87.  
  88.  
  89.  
  90. class CoreConnection;
  91.  
  92. //.......................................
  93. // CoreHead
  94.  
  95. class CoreHead: public CoreNode
  96. {
  97.  
  98.     //***********************************************************
  99.     //.............. P U B L I C   M E T H O D S.................
  100.  
  101.     public:
  102.  
  103.     CoreHead(long nentry=0);                                // Object unlinked
  104.     CoreHead(CoreList *, long nentry);                     // Object linked to a CoreList
  105.     CoreHead(CoreHead *, long headentry,long nentry=0);   // Object under control of a CoreHead
  106.  
  107.  
  108.     virtual ~CoreHead(void);   // Delete all entries, sub coreheads,...
  109.  
  110.  
  111.     virtual void setlist(CoreList *a);                          // Link to a list
  112.     virtual void setsupervisor(CoreHead *a, long headentry=0); // Place under control of a CoreHead
  113.     
  114.     virtual void setsupervisor(CoreHead *a, 
  115.                                long headentry, 
  116.                                long listposition);   // Places under control of a CoreHead "a".
  117.                                                         // "listposition" allows you to specify
  118.                                                         // an offset in the destination list.
  119.                                                         // Use this method to move a
  120.                                                         // CoreHead to a new position in its
  121.                                                         // list. 
  122.  
  123.     virtual void setsamesupervisoras(CoreHead *a, Boolean insertbefore =FALSE);
  124.                                                    // Places under the same supervisor of the
  125.                                                       // CoreHead "a". If "insertbefore" is TRUE
  126.                                                       // object is inserted before the CoreHead "a"
  127.                                                       // else it is inserted after.
  128.  
  129.     virtual void setnentry(long nentry);                      // Change number of entries
  130.  
  131.  
  132.     inline CoreHead *getsupervisor(void) const {return supervisor;}
  133.     inline long getnentry(void) const {return nentry;}
  134.     inline CoreList *getentry(long entry=0) const {if (entry<nentry) return entrytab[entry];
  135.                                                                 else return NULL;}
  136.  
  137.  
  138.  
  139.     virtual void remove(void);          // Remove this object from its list and/or its
  140.                                        // supervisor.
  141.  
  142.     virtual Core *duplicate(void);            // Duplicate. If this object has a list, the
  143.                                            // duplicated object is linked to the same
  144.                                          // list. Use "remove" if you want to unlink
  145.                                         // the duplicated object.
  146.  
  147.     virtual long addentry(void);   // Add a new entry.
  148.  
  149.     virtual void flushentry(const long entry =0); // Delete all the nodes linked to the
  150.                                                  // specified entry.
  151.  
  152.     // If you do not want to specify an entry number directly, you
  153.     // can use the two following methods. These methods allow you to allocate
  154.     // and free entries without having to specify an entry number. When you
  155.     // want a new entry you call "allocentry" which returns the number of
  156.     // the new entry. You can work with this value without having to know
  157.     // entry position. When you don't need an entry anymore, simply
  158.     // call "freeentry" with the value returned by "allocentry". Be sure to
  159.     // never use a deleted entry. Note that you don't have to free entries
  160.     // before deleting the CoreHead. CoreHead is smart enough to delete all
  161.     // entries within his destructor.
  162.  
  163.     virtual long allocentry(void);            // Alloc a new entry, search the best entry position
  164.     virtual void freeentry(long entry);        // Free an entry allocated by "allocentry"
  165.  
  166.  
  167.     virtual void docmd(long cmd,
  168.                                short flags=0,
  169.                                void *info=NULL,
  170.                                short t=0,
  171.                                void *parent=NULL); // Send a command
  172.  
  173.  
  174.     //.....................
  175.     // CCL version 1.1, connection system
  176.  
  177.     virtual void connectto(CoreHead *head, long connectionID =0);
  178.     virtual void deconnect(CoreHead *head);
  179.     
  180.     virtual CoreHead *getconnection(long p =0);
  181.     virtual CoreHead *getconnection_by_id(long connectionID);
  182.     inline long getnconnections(void) {return connections_list->getlength();}
  183.  
  184.     virtual void setconnection_id(CoreHead *head, long connectionID);
  185.     virtual long getconnection_id(CoreHead *head);
  186.  
  187.     virtual void deconnectall();            // Deletes all of its connections
  188.     virtual void deconnect_from_watchers();    // Deletes all watchers connections which
  189.                                             // are connected to this object
  190.     
  191.     Boolean isconnectedto(CoreHead *head);
  192.  
  193.     virtual CoreHead *getwatcher(long p =0);
  194.     inline long getnwatchers(void) {return connectwatchers_list->getlength();}
  195.  
  196.  
  197.     //***********************************************************
  198.  
  199.  
  200.     protected:
  201.  
  202.     virtual CoreList *newentry(void);            // Alloc a new entry. You can override
  203.                                                 // this method if you want CoreHead to
  204.                                                 // build a superclass of CoreList.
  205.  
  206.     virtual void receivecmd(long cmd, void *info);
  207.  
  208.  
  209.     public:
  210.  
  211.     //..........................................................
  212.     // You should not call the following methods!
  213.  
  214.     inline CoreList    *getconnections_list(void) {return connections_list;}
  215.     inline CoreList    *getconnectwatchers_list(void) {return connectwatchers_list;}
  216.  
  217.     virtual void copyfrom(Core *uo);         // The magic duplication system (see core.h)
  218.     virtual void sendcmd(long cmd, short flags, void *info, short t, void *parent=NULL);
  219.     // (Don't call this method, use docmd instead. Only for internal use).
  220.  
  221.     //..........................................................
  222.  
  223.  
  224.     private:
  225.  
  226.     CoreHead   *supervisor;        // Its supervisor or NULL
  227.  
  228.     CoreList     **entrytab;      // Objects under control, entries tab
  229.     long            nentry;         // Number of entries
  230.  
  231.     CoreList    *connections_list;
  232.     CoreList    *connectwatchers_list;
  233.     Boolean        connectalreadypassed;    
  234. };
  235.  
  236. //.................................................................
  237. // When you receive a CCMD_CONNECTIONDELETED and CCMD_WATCHERDELETED message, 
  238. // the "info" field points on the following structure:
  239.  
  240. struct ConnectionDeletedInfo
  241. {
  242.     CoreHead    *deletedobject;        // The deleted object (don't try to use it)
  243.     long        connectionID;        // ID of the connection
  244.     Boolean        deletemyself;        // If TRUE the receiver will be deleted (default FALSE)
  245. };
  246.  
  247. #endif
  248.  
  249.